package com.zenith.yasoo.catalog;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.sun.istack.internal.NotNull;
import com.zui.base.BaseEntity;

@Entity
@Table(name = "catalog")
public class Catalog extends BaseEntity {
	private static final long serialVersionUID = 1L;

	private String catalogCode;
	private String catalogName;
	private Catalog parentCatalog;
	private Set<Catalog> childCategories = new LinkedHashSet<Catalog>();
	
	/*------------------------------
	 * getters and annotations
	 --------------------------------*/	
	
	@Column(length = 30, unique = true) @NotNull
	public String getCatalogCode() {return catalogCode;}

	@Column(length = 50) @NotNull
	public String getCatalogName() {return catalogName;}

	@ManyToOne() @JoinColumn(name="parentCatalogId")
	public Catalog getParentCatalog() {return parentCatalog;}

	@OneToMany(mappedBy = "parentCatalog", fetch = FetchType.LAZY)
	@OrderBy(value = "catalogName asc")
	public Set<Catalog> getChildCategories() {return childCategories;}

	/*------------------------------
	 * setters
	 --------------------------------*/
	public void setCatalogCode(String catalogCode) {this.catalogCode = catalogCode;}
	public void setCatalogName(String catalogName) {
		this.catalogName = catalogName;
	}
	public void setParentCatalog(Catalog parentCatalog) {
		this.parentCatalog = parentCatalog;
	}
	public void setChildCategories(Set<Catalog> childCategories) {
		this.childCategories = childCategories;
	}


}
